home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / PowerMacOberon feb96 / Dialogs / MoreMathL.Mod (.txt) < prev    next >
Encoding:
Oberon Text  |  1995-06-30  |  6.7 KB  |  168 lines  |  [TEXT/.Ob4]

  1. Syntax10.Scn.Fnt
  2. InfoElems
  3. Alloc
  4. Syntax10.Scn.Fnt
  5. StampElems
  6. Alloc
  7. 8 Feb 95
  8. "Title": MoreMathL
  9. "Author": Christoph Steindl (CS)
  10. "Abstract": Implementation of the mathematical functions not exported by MathL. The previously used 
  11.     MathLib shipped with the Metrowerks C-Compiler was slow and inaccurate.
  12. "Keywords": trigonimetric functions, inverse trigonometric functions, hyperbolic functions, inverse
  13.     hyperbolic functions, IEEE floating-point format
  14. "Version": 1.0
  15. "From":  11.11.94 15:40:26
  16. "Until": 
  17. "Changes": 
  18. "Hints": This text can again contain arbitrary text elements!
  19. Syntax10i.Scn.Fnt
  20. StampElems
  21. Alloc
  22. 8 Feb 95
  23. FoldElems
  24. Syntax10.Scn.Fnt
  25. Floating point format according to the IEEE standard
  26. Courier10.Scn.Fnt
  27. Syntax10.Scn.Fnt
  28. Implementation hierarchy
  29. KeplerElems
  30. Alloc
  31. KeplerGraphs
  32. GraphDesc
  33. KeplerGraphs
  34. StarDesc
  35. KeplerFrames
  36. CaptionDesc
  37. Syntax10.Scn.Fnt
  38. Kepler1
  39. AttrDesc
  40. Cosin
  41. Syntax10.Scn.Fnt
  42. ArcTan
  43. Syntax10.Scn.Fnt
  44. Syntax10.Scn.Fnt
  45. Syntax10.Scn.Fnt
  46. Syntax10.Scn.Fnt
  47. Tangens
  48. Syntax10.Scn.Fnt
  49. Cotangens
  50. Syntax10.Scn.Fnt
  51. ArcSin
  52. Syntax10.Scn.Fnt
  53. ArcCot
  54. Syntax10.Scn.Fnt
  55. ArcCos
  56. Syntax10.Scn.Fnt
  57. Syntax10.Scn.Fnt
  58. Syntax10.Scn.Fnt
  59. Syntax10.Scn.Fnt
  60. Syntax10.Scn.Fnt
  61. ArcTanh
  62. Syntax10.Scn.Fnt
  63. ArcSinh
  64. Syntax10.Scn.Fnt
  65. ArCosh
  66. Syntax10.Scn.Fnt
  67. ArCoth
  68. Syntax10.Scn.Fnt
  69. "exported from MathL"
  70. Syntax10.Scn.Fnt
  71. Kepler1
  72. LineDesc
  73. Syntax10b.Scn.Fnt
  74. MODULE MoreMathL;    
  75.     (* Christoph Steindl (CS), 11.11.94 - 
  76. IMPORT SYSTEM, MathL;
  77. CONST 
  78.     piOver2 = MathL.pi / 2;
  79.     Floating point format according to the IEEE standard:
  80.     single precision: S EEEEEEEE MMMMMMMMMMMMMMMMMMMMMMM
  81.         1 bit for the sign
  82.         8 bits for the exponent
  83.         23 bits for the mantissa
  84.         ____________________________________________________________________________________________________
  85.         32 bits = 4 bytes for one single precision floating point number
  86.         The exponent is stored as an unbiased exponent, to get the real exponent (within range -126..127) you have to
  87.         subtract 127 from the resulting number).
  88.         The number 0 is represented as exponent = 0 and mantissa = 0.
  89.         An exponent of 255 and a mantissa of 0 denotes infinity.
  90.         An exponent of 255 and a mantissa of #0 denotes NaN.
  91.     double precision: S EEEEEEEEEEE MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
  92.         1 bit for the sign
  93.         11 bits for the exponent
  94.         52 bits for the mantissa
  95.         ______________________________________________________________________________________________________
  96.         64 bits = 8 bytes for one double precision floating point number
  97.         The exponent is stored as an unbiased exponent, to get the real exponent (within range -1022..1024) you have
  98.         to subtract 1023 from the resulting number).
  99.         The number 0 is represented as exponent = 0 and mantissa = 0.
  100.         An exponent of 2047 and a mantissa of 0 denotes infinity.
  101.         An exponent of 2047 and a mantissa of #0 denotes NaN.
  102. in NNMathL.Dep.Kep *)
  103. PROCEDURE tan* (x: LONGREAL): LONGREAL;
  104.     VAR neg: BOOLEAN; y, s1: LONGREAL;
  105. BEGIN
  106.     y := x - ENTIER(x / MathL.pi) * MathL.pi;
  107.     IF y > piOver2 THEN neg := TRUE ELSE neg := FALSE END;
  108.     s1 := MathL.sin(y);
  109.     IF neg THEN RETURN - s1 / MathL.sqrt(1 - s1 * s1) ELSE RETURN s1 / MathL.sqrt(1 - s1 * s1) END
  110. END tan;
  111. PROCEDURE cot* (x: LONGREAL): LONGREAL;
  112.     BEGIN RETURN 1 / tan(x) END cot;
  113. PROCEDURE arcsin* (x: LONGREAL): LONGREAL;
  114.     BEGIN RETURN MathL.arctan(x / MathL.sqrt(1 - x * x)) END arcsin;
  115. PROCEDURE arccot* (x: LONGREAL): LONGREAL;
  116.     BEGIN RETURN piOver2 - MathL.arctan(x) END arccot;
  117. PROCEDURE arccos* (x: LONGREAL): LONGREAL;
  118.     BEGIN RETURN piOver2 - arcsin(x) END arccos;
  119. PROCEDURE tanh* (x: LONGREAL): LONGREAL;
  120.     VAR e1, e2, e3, e4, e5, e6, t1, t2: LONGREAL;
  121. BEGIN
  122.     IF ABS(x) < 3.7D-9 THEN RETURN x
  123.     ELSIF x >= 20.101 THEN RETURN 1
  124.     ELSIF x <= -0.54931D0 THEN RETURN - tanh(-x)
  125.     ELSIF x >= 0.54931 THEN RETURN 1 - 2 / (MathL.exp(2 * x) + 1) 
  126.     ELSE
  127.         (* with Mathematica: 
  128.             <<Calculus`Pade`
  129.             N[EconomizedRationalApproximation[Tanh[x], {x, {-0.1, 0.6}, 6, 6}], 20]
  130.         e1 := (-0.25 + x); e2 := e1 * (-0.25 + x); e3 := e2 * (-0.25 + x); e4 := e3 * (-0.25 + x);
  131.         e5 := e4 * (-0.25 + x); e6 := e5 * (-0.25 + x);
  132.         t1 := 0.00002356119887556018 * e6 + 0.002023148148112773 * e5 + 
  133.             0.004958685234944415 * e4 + 0.1215218750947677 * e3 +
  134.             0.1116301731341965 * e2 + 1.002788402136751 * e1 + 0.2456015941258246;
  135.         t2 := 0.0000962000961977488 * e6 + 0.0004955067381496328 * e5 +
  136.             0.02024625313240082 * e4 + 0.02976297509725574 * e3 +
  137.             0.4557846758065249 * e2 + 0.2456015941168399 * e1 + 1.002788402138951;
  138.         RETURN t1 / t2
  139.     END;
  140. END tanh;
  141. PROCEDURE sinh* (x: LONGREAL): LONGREAL;
  142.     VAR t1: LONGREAL;
  143. BEGIN
  144.     t1 := tanh(x);
  145.     RETURN t1 / MathL.sqrt(1 - t1 * t1)
  146. END sinh;
  147. PROCEDURE cosh* (x: LONGREAL): LONGREAL;
  148.     VAR t1: LONGREAL;
  149. BEGIN
  150.     t1 := tanh(x);
  151.     RETURN 1 / MathL.sqrt(1 - t1 * t1)
  152. END cosh;
  153. PROCEDURE coth* (x: LONGREAL): LONGREAL;
  154.     VAR e1, e2: LONGREAL;
  155. BEGIN
  156.     e1 := MathL.exp(x); e2 := 1 / e1;
  157.     RETURN (e1 + e2) / (e1 - e2)
  158. END coth;
  159. PROCEDURE arctanh* (x: LONGREAL): LONGREAL;
  160.     BEGIN RETURN 0.5 * MathL.ln((1 + x) / (1 - x)) END arctanh;
  161. PROCEDURE arcsinh* (x: LONGREAL): LONGREAL;
  162.     BEGIN RETURN arctanh(x / MathL.sqrt(1 + x * x)) END arcsinh;
  163. PROCEDURE arcosh* (x: LONGREAL): LONGREAL;
  164.     BEGIN RETURN arctanh(MathL.sqrt(x * x - 1) / x) END arcosh;
  165. PROCEDURE arcoth* (x: LONGREAL): LONGREAL;
  166.     BEGIN RETURN arctanh(1 / x) END arcoth;
  167. END MoreMathL.Mod
  168.